package o;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.share.api.ShareBean;
import com.huawei.appgallery.share.protocol.WBEntryActivityProtocol;
import com.huawei.appgallery.share.protocol.WBEntryActivityProtocol.Request;
import com.sina.weibo.sdk.WbSdk;
import com.sina.weibo.sdk.auth.AuthInfo;
import com.sina.weibo.sdk.share.WbShareHandler;
import o.cwj.c;
import o.cwj.i;
import o.dge.d;

public class cxj extends cxg {
    private boolean ʻ;
    private BroadcastReceiver ʼ = new BroadcastReceiver(this) {
        final /* synthetic */ cxj ˏ;

        {
            this.ˏ = r1;
        }

        public void onReceive(Context context, Intent intent) {
            if (this.ˏ.ॱ != null) {
                this.ˏ.ॱ.ॱ();
            }
        }
    };
    private WbShareHandler ʽ = null;
    private String ˊ = "";
    private cxi ˋ;
    private ShareBean ˎ;
    private boolean ˏ;
    private DownloadButton ॱ;
    private String ॱॱ;
    private boolean ᐝ = false;

    class a implements eqz {
        final /* synthetic */ cxj ˏ;

        private a(cxj o_cxj) {
            this.ˏ = o_cxj;
        }

        public void ॱ(Bitmap bitmap) {
            if (this.ˏ.ʻ) {
                cwr.ॱ.ˋ("WeiboShareHandler", "activity is destroy.");
                return;
            }
            Bitmap bitmap2 = null;
            if (bitmap != null) {
                bitmap2 = cxw.ˊ(bitmap.copy(Config.ARGB_8888, true), cwv.ॱ().ˎ());
                cwr.ॱ.ˋ("WeiboShareHandler", "weibo get net bitmap success!");
            } else {
                cwr.ॱ.ˋ("WeiboShareHandler", "weibo get net bitmap failed!");
            }
            this.ˏ.ˎ(this.ˏ.ˋ.ᐝ(), bitmap2);
        }
    }

    class b extends cxd {
        final /* synthetic */ cxj ˎ;
        private boolean ˏ = false;

        public b(cxj o_cxj, boolean z) {
            this.ˎ = o_cxj;
            this.ˏ = z;
        }

        public void ˎ(Context context, String str, String str2) {
            this.ˎ.ˊ = str2;
            this.ˎ.ˊ();
            if (!this.ˏ) {
                dgh.onEvent(new d(ContentManager.getInstant().getContext(), i.ˎ).ˏ("03" + '|' + UserSession.getInstance().getUserId() + '|' + this.ˎ.ˎ.ʻ()).ˋ());
                this.ˎ.ʻ();
            }
        }
    }

    public String ˎ() {
        return "com.sina.weibo";
    }

    public boolean ˊ(ShareBean shareBean) {
        return super.ॱ(shareBean.ͺ(), 4, shareBean.ˏॱ());
    }

    public boolean ˏ(cxi o_cxi, LinearLayout linearLayout, LayoutInflater layoutInflater, boolean z, ShareBean shareBean) {
        this.ˋ = o_cxi;
        this.ˎ = shareBean;
        View inflate = layoutInflater.inflate(cwj.d.ˊ, null);
        ((TextView) inflate.findViewById(c.ˋ)).setText(i.ˈ);
        ((ImageView) inflate.findViewById(c.ॱ)).setImageResource(cwj$b.ˋ);
        this.ॱ = (DownloadButton) inflate.findViewById(c.ʽ);
        o_cxi.ˋ(ˎ(), this.ॱ);
        linearLayout.addView(inflate);
        inflate.setOnClickListener(new evx(this) {
            final /* synthetic */ cxj ˏ;

            {
                this.ˏ = r1;
            }

            public void ˋ(View view) {
                cwr.ॱ.ˋ("WeiboShareHandler", "click share to weibo!");
                if (!doo.ˊ(this.ˏ.ˋ.ᐝ())) {
                    evk.ˋ(this.ˏ.ˋ.ᐝ(), this.ˏ.ˋ.ᐝ().getString(i.ʻ), 0).ˋ();
                } else if (!cxp.ˏ(this.ˏ.ˋ.ᐝ(), this.ˏ.ˎ())) {
                    cwr.ॱ.ˋ("WeiboShareHandler", "Weixin not installed.Show Download Button");
                    this.ˏ.ˋ(this.ˏ.ˋ.ᐝ());
                } else if ("appdetail".equals(this.ˏ.ˎ.ʼ())) {
                    this.ˏ.ˏ(this.ˏ.ˋ.ᐝ().getPackageName());
                } else {
                    this.ˏ.ˊ(this.ˏ.ˋ.ᐝ(), false);
                }
            }
        });
        ˊ(this.ˋ.ᐝ(), true);
        this.ˋ.registerReceiver(this.ʼ, new IntentFilter(ccv.ˋ()));
        return true;
    }

    private void ˊ(Context context, boolean z) {
        cxo.ˎ(context.getString(i.ˏॱ), context, new b(this, z));
    }

    public void ˎ(ShareBean shareBean) {
        this.ʻ = true;
        this.ˋ.unregisterReceiver(this.ʼ);
    }

    public void ˏ() {
        this.ˏ = false;
    }

    public void ॱ() {
        if (!this.ᐝ && this.ˏ) {
            this.ˏ = false;
            ˎ(this.ˋ.ᐝ(), this.ˋ.ᐝॱ().getAttValueTypeName());
        }
    }

    private void ˊ() {
        if (this.ʽ != null) {
            cwr.ॱ.ˎ("WeiboShareHandler", "weibo api has inited.");
        } else if (this.ˊ != null) {
            WbSdk.install(this.ˋ.ᐝ(), new AuthInfo(this.ˋ.ᐝ(), this.ˊ, this.ˋ.ᐝ().getString(i.ˊॱ), "email,direct_messages_read,direct_messages_write,friendships_groups_read,friendships_groups_write,statuses_to_me_read,follow_app_official_microblog,invitation_write"));
            this.ʽ = new WbShareHandler((Activity) this.ˋ.ᐝ());
            this.ʽ.registerApp();
            cwr.ॱ.ˋ("WeiboShareHandler", "init weibo api !");
        } else {
            cwr.ॱ.ˊ("WeiboShareHandler", "weibo AppKey is null.");
        }
    }

    private void ʻ() {
        if (!doo.ˊ(this.ˋ.ᐝ())) {
            evk.ˋ(this.ˋ.ᐝ(), this.ˋ.ᐝ().getString(i.ʻ), 0).ˋ();
        } else if (this.ʽ != null && WbSdk.isWbInstall(this.ˋ.ᐝ())) {
            Object ˊ = cwv.ॱ().ˊ();
            if (!"appdetail".equals(this.ˎ.ʼ()) || TextUtils.isEmpty(ˊ)) {
                cxi$d ᐝॱ = this.ˋ.ᐝॱ();
                if (ᐝॱ.ˏ()) {
                    Bitmap ॱ = ᐝॱ.ॱ();
                    if (ॱ == null) {
                        ॱ = ॱ(cxw.ॱ(this.ˋ.ᐝ(), this.ˎ.ˏ()));
                    }
                    ˎ(this.ˋ.ᐝ(), ॱ);
                    return;
                }
                this.ˏ = true;
                this.ˋ.ͺ();
                return;
            }
            this.ᐝ = true;
            eqx.ॱ(this.ˋ.ᐝ(), ˊ, new a());
        }
    }

    private Bitmap ॱ(Bitmap bitmap) {
        cwr.ॱ.ˋ("WeiboShareHandler", "click share to weixin zone!");
        if (bitmap == null) {
            return null;
        }
        Bitmap copy = bitmap.copy(Config.ARGB_8888, true);
        Canvas canvas = new Canvas(copy);
        canvas.drawColor(-1);
        canvas.drawBitmap(bitmap, 0.0f, 0.0f, null);
        return copy;
    }

    private void ˏ(String str) {
        cwm.ˊ().ˊ(str, new cwx(this) {
            final /* synthetic */ cxj ˏ;

            {
                this.ˏ = r1;
            }

            public void ˊ(cwy o_cwy) {
                if (o_cwy != null) {
                    this.ˏ.ॱॱ = o_cwy.ˋ();
                }
                this.ˏ.ˊ(this.ˏ.ˋ.ᐝ(), false);
            }
        });
    }

    private void ˋ(Context context) {
        cke ॱ = this.ॱ.ॱ();
        for (View view : this.ˋ.ˊ(ˎ())) {
            if (view != this.ॱ) {
                view.setVisibility(8);
            }
        }
        if (ॱ == cke.ˊ) {
            cwm.ˊ().ˊ(ˎ(), new cwx(this) {
                final /* synthetic */ cxj ॱ;

                {
                    this.ॱ = r1;
                }

                public void ˊ(cwy o_cwy) {
                    if (o_cwy != null) {
                        BaseDistCardBean baseDistCardBean = new BaseDistCardBean();
                        baseDistCardBean.ˏॱ(o_cwy.ˋ());
                        baseDistCardBean.ˋॱ(o_cwy.ॱॱ());
                        baseDistCardBean.ˏˎ(o_cwy.ˊ());
                        baseDistCardBean.ˋ(o_cwy.ʻ());
                        baseDistCardBean.ˋᐝ(o_cwy.ॱ());
                        try {
                            baseDistCardBean.ॱ(Long.parseLong(o_cwy.ˏ()));
                        } catch (NumberFormatException e) {
                            cwr.ॱ.ˊ("WeiboShareHandler", "size error");
                        }
                        baseDistCardBean.ˉ(o_cwy.ᐝ());
                        baseDistCardBean.ॱ(o_cwy.ʽ());
                        baseDistCardBean.ˎ(o_cwy.ˎ());
                        baseDistCardBean.ॱ(o_cwy.ʼ());
                        baseDistCardBean.ͺ(o_cwy.ˋॱ());
                        this.ॱ.ॱ.setParam(baseDistCardBean);
                        this.ॱ.ॱ.setVisibility(0);
                        this.ॱ.ॱ.ॱ();
                    }
                }
            });
        } else {
            this.ॱ.setVisibility(0);
            this.ॱ.ॱ();
        }
        evk.ˏ(context, i.ʿ, 1).ˋ();
    }

    private void ˎ(Context context, Bitmap bitmap) {
        String string;
        byte[] ˏ;
        cjo wBEntryActivityProtocol = new WBEntryActivityProtocol();
        Request request = new Request();
        request.ˋ(cxw.ॱ(this.ˋ.ᐝ(), this.ˎ.ʻ(), "xinlang"));
        if (!"appdetail".equals(this.ˎ.ʼ())) {
            string = context.getString(i.ˋˊ, new Object[]{this.ˎ.ˊ(), r3});
        } else if (this.ˎ.ˋॱ()) {
            string = context.getString(i.ˊˋ, new Object[]{this.ˎ.ॱ(), cwv.ॱ().ˋ(), r3, this.ॱॱ});
        } else {
            string = context.getString(i.ˉ, new Object[]{this.ˎ.ॱ(), cwv.ॱ().ˋ(), r3, this.ॱॱ});
        }
        if (this.ˎ.ˊॱ() == 3 && !TextUtils.isEmpty(this.ˎ.ˊ())) {
            string = context.getString(i.ˋˊ, new Object[]{this.ˎ.ˊ(), r3});
        }
        request.ˎ(string);
        if (bitmap == null) {
            bitmap = BitmapFactory.decodeResource(context.getResources(), cwj$b.ᐝ);
        }
        if ("appdetail".equals(this.ˎ.ʼ())) {
            ˏ = cxw.ˏ(bitmap, 900, 85, cxw.ˏ(cwv.ॱ().ˊ()));
        } else {
            ˏ = cxw.ˏ(bitmap, 900, 85, cxw.ˏ(this.ˎ.ˋ()));
        }
        request.ˎ(ˏ);
        wBEntryActivityProtocol.ˎ(request);
        cjk.ˎ().ˋ(context, new cjm("wb_entry.activity", wBEntryActivityProtocol));
        this.ˋ.finish();
    }
}
